package com.hxkj.controller;

import com.alicp.jetcache.ResultData;
import com.hxkj.domain.po.Channel;
import com.hxkj.service.ChannelService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @ClassName ChannelController
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/6/7 11:56
 * @Version 1.0
 */
@RestController
@RequestMapping("/channel")
public class ChannelController {
    @Autowired
    ChannelService channelService;

    /**
    * @author Mr.zheng
    * @Description saveChannel 新增频道
    * @Date 17:53 2018/6/7
    **/
    @RequestMapping(value = "/save", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> saveChannel(@RequestBody Channel channel) throws Exception{
        return () -> channelService.saveChannel(channel);
    }


    /**
    * @author Mr.zheng
    * @Description getChannelList 获取频道列表
    * @Date 17:54 2018/6/7
    **/
    @RequestMapping(value = "/getlist", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Channel>> getChannelList(@RequestBody ParameterDataStruct<Channel> parameterDataStruct) throws Exception{
        return () -> ResultStructUtils.buildResultPageStruct(channelService.getChannelList(parameterDataStruct.getData() == null ?
                new Channel() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()),"param=value");
    }


    /**
    * @author Mr.zheng
    * @Description getChannel 有条件获取频道
    * @Date 17:54 2018/6/7
    **/
    @RequestMapping(value = "/get", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Channel>> getChannel(@RequestBody Channel channel) throws Exception{
        return () -> channelService.getChannel(channel);

    }


    /**
    * @author Mr.zheng
    * @Description removerChannel 删除频道
    * @Date 17:54 2018/6/7
    **/
    @RequestMapping(value = "/remove", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> removeChannel(@RequestBody  Channel channel) throws Exception{
        return () -> channelService.removeChannel(channel);
    }


    /**
    * @author Mr.zheng
    * @Description modifyChannel 修改频道
    * @Date 17:55 2018/6/7
    **/
    @RequestMapping(value = "/modify", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> modifyChannel(@RequestBody Channel channel) throws Exception{
        return () -> channelService.modifyChannel(channel);
    }


    /**
     * @author Mr.zheng
     * @Description modifyChannel 根据站点获取所有频道
     * @Date 17:55 2018/6/7
     **/
    @RequestMapping(value = "/getAllChannel", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Channel>>> getAllChannel(@RequestBody Channel channel) throws Exception{
        return () -> channelService.getAllChannel(channel);
    }

    /**
     * 通过站点id获取所有的频道
     * chenfangzhou
     */
    @RequestMapping(value = "/getListBySiteId", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Channel>>> getListBySiteId(@RequestBody Channel channel) throws Exception{
        return () -> channelService.getListBySiteId(channel);
    }


    /**
     * @author Mr.zheng
     * @Description getChannelByTempletId 根据站点ID和模板ID获取一条绑定了该模板的频道数据
     * @Date 14:47 2018/8/16
     **/
    @RequestMapping(value = "/getChannelByTempletId", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Channel>> getChannelByTempletId(@RequestBody Channel channel) throws Exception{
        return () -> channelService.getChannelByTempletId(channel);
    }
}
